//
//  XDPersonalCommentViewController.m
//  XDEducation
//
//  Created by apple on 2017/4/19.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "XDPersonalCommentViewController.h"
#import "XDPersonCommentCell.h"
#import "XDPersonalCommentModel.h"
@interface XDPersonalCommentViewController ()
/** 数据源 */
@property(nonatomic,strong) NSMutableArray *personCommentModel;
@end

static NSString *const cellId = @"PersonalCommentCell";

@implementation XDPersonalCommentViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initNetworkingWithRefreshStatus:RefreshStatePullDown];
}


-(NSMutableArray *)personCommentModel{
    if(!_personCommentModel){
        _personCommentModel = [NSMutableArray array];
    }
    return _personCommentModel;
}

#pragma mark - tableview delegate

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.personCommentModel.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 85 * ScaleHeight;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView registerNib:[UINib nibWithNibName:@"XDPersonCommentCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:cellId];
    XDPersonCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    cell.personalCommentModel = self.personCommentModel[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}


-(void)initNetworkingWithRefreshStatus:(RefreshState)status{

    NSString *url = BaseURL(@"homework.do?action=getRemarkInfo");
    NSDictionary *dict = @{@"uid":[AccountTool shareAccountTool].currentAccount.uid,@"pageNumber":@(self.pageNumber)};
    [MBProgressHUD showHUD];
    [XDHttpTool get:url authCode:[AccountTool shareAccountTool].currentAccount.authCode params:dict success:^(id responseObj) {
        [MBProgressHUD hideHUD];
        //NSLog(@"%@",responseObj);
        NSArray *dictArr = responseObj;
        NSMutableArray *modelArr = [NSMutableArray array];
        
        for (NSDictionary *dict in dictArr) {
            XDPersonalCommentModel *model = [XDPersonalCommentModel personalCommentModelWithDict:dict];
            [modelArr addObject:model];
        }
        
        self.personCommentModel = modelArr;
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        [MBProgressHUD hideHUD];
        [MBProgressHUD showError:XDNetWorkError];
        NSLog(@"%@",error);
        
    }];
    
}
@end
